package com.itheima.functinalInterface;

import com.itheima.lambda.Student;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Predicate;

public class MyPredicateDemo {
    
    public static List<Student> filter(List<Student> studentList, Predicate<Student> predicate) {
        
        List<Student> list = new ArrayList<>();
        
        studentList.forEach(s -> {
            
            if (predicate.test(s)) {
                list.add(s);
            }
        });
        
        return list;
    }
    
    public void demo() {
        
        int port = 8086;
        Runnable runnable = () -> System.out.println(port);
    }
    
    public static void main(String[] args) {
        
        List<Student> students = new ArrayList<>();
        students.add(new Student(1, "张三", "M"));
        students.add(new Student(2, "李四", "M"));
        students.add(new Student(3, "王五", "F"));
        Predicate<Student> predicate = student -> student.getSex().equals("F");
        // predicate.and()
        // List<Student> res1 = students.stream().filter(predicate).collect(Collectors.toList());
        // System.out.println(res1);
        ;
        List<Student> list = new ArrayList<>();
        Consumer<Student> consumer = student -> {
            if (predicate.test(student)) {
                list.add(student);
            }
        };
        students.forEach(consumer);
        System.out.println(list);
        // List<Student> result = filter(students, (s) -> s.getSex().equals("F"));
        //
        // System.out.println(result.toString());
    }
}
